package com.wanger.swa.config.autoDDL;

import cn.hutool.core.date.DateUtil;
import com.wanger.swa.service.ise.DataSourceService;
import lombok.RequiredArgsConstructor;
import lombok.extern.slf4j.Slf4j;
import org.anyline.util.ConfigTable;
import org.springframework.boot.ApplicationArguments;
import org.springframework.boot.ApplicationRunner;
import org.springframework.stereotype.Component;

/**
 * @Author: wanger
 * @Date: 2025/1/17 14:48
 * @Description:
 */
@Slf4j
@Component
@RequiredArgsConstructor
public class DataSourceStartupRunner implements ApplicationRunner {

    private final DataSourceService dataSourceService;

    static {
        //设置元数据不缓存
        ConfigTable.METADATA_CACHE_SCOPE = 0;
    }

    /**
     * mybatis-plus启动时回调
     *
     * @param args 启动参数
     */
    @Override
    public void run(ApplicationArguments args) {
        log.info("开始注册数据源！");
        long l = System.currentTimeMillis();
        dataSourceService.registerAllDataSources();
        log.info("数据源注册完成！用时【{}】！", DateUtil.formatBetween(System.currentTimeMillis() - l));
    }

}
